import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Mint from 'mint-ui'
import 'mint-ui/lib/style.css'
import './assets/css/common.css'
import './assets/css/my-mint.scss'
// import '../public/js/jquery-1.7.2.min'
import BScroll from "better-scroll";

Vue.use(Mint);

Vue.config.productionTip = false


// qs
import qs from 'qs'

Vue.prototype.qs = qs;

// axios
import axios from '../public/js/https'

axios.defaults.withCredentials = true
Vue.prototype.$ajax = axios;

new Vue({
    router,
    store,
    BScroll,
    render: h => h(App)
}).$mount('#app')


//路由守卫
router.beforeEach((to, from, next) => {
    // console.log(localStorage.getItem("token"))
    // console.log(to.meta,from,next)
    if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if (localStorage.getItem('token')) { //判断本地是否存在token
            next();
        } else {
            if (to.path === '/index') {
                next();
            } else {
                next({
                    path: '/login'
                })
            }
        }
    }
    else {
        next();
    }
    /*如果本地 存在 token 则 不允许直接跳转到 登录页面*/
    if (to.fullPath == "/login") {
        if (localStorage.getItem('token')) {
            next({
                path: from.fullPath
            });
        } else {
            next();
        }
    }
});
